﻿Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Runtime.Serialization


''' <summary>
''' An event handled by a projection and what occurs due to it
''' </summary>
<Serializable>
<DataContract(Name:=NameOf(EventHandledModel))>
Public NotInheritable Class EventHandledModel
    Implements INotifyPropertyChanged
    Implements IEquatable(Of EventHandledModel)

    Private ReadOnly m_eventName As String
    ''' <summary>
    ''' The name of the event handled by the projection
    ''' </summary>
    ''' <remarks>
    ''' Each event type may only appear once in the list
    ''' </remarks>
    Public ReadOnly Property EventName As String
        Get
            Return m_eventName
        End Get
    End Property

    Private m_propertyOperations As New List(Of EventPropertyOperationModel)

    ''' <summary>
    ''' The property operations performed when this event is received
    ''' </summary>
    Public ReadOnly Property PropertyOperations As IEnumerable(Of EventPropertyOperationModel)
        Get
            Return m_propertyOperations
        End Get
    End Property

    Public Sub AddPropertyOperation(ByVal operationToAdd As EventPropertyOperationModel)
        m_propertyOperations.Add(operationToAdd)
        OnPropertyChanged(NameOf(PropertyOperations))
    End Sub

#Region "Property Change Notification"
    Public Sub OnPropertyChanged(ByVal propertyName As String)

        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))

    End Sub
    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
#End Region

#Region "Equality"

    Public Overrides Function Equals(obj As Object) As Boolean

        If (TypeOf (obj) Is EventHandledModel) Then
            Return EqualsEventHandledModel(obj)
        Else
            Return False
        End If

    End Function

    ''' <summary>
    ''' Are the two event handled models the same
    ''' </summary>
    ''' <param name="other">
    ''' The event handled model to compare against
    ''' </param>
    ''' <returns>
    ''' True if the two models relate to the same event
    ''' </returns>
    Public Overloads Function EqualsEventHandledModel(other As EventHandledModel) As Boolean Implements IEquatable(Of EventHandledModel).Equals

        If (other IsNot Nothing) Then
            Return m_eventName.Equals(other.EventName)
        Else
            Return False
        End If

    End Function

#End Region

    Public Sub New(ByVal eventNameHandled As String)
        m_eventName = eventNameHandled
    End Sub

End Class
